﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using FXnaInfrastructure;

namespace ASAermod.FileLayers
{


    public class SOITEM
    {

        string _SRCID;

        public string SRCID
        {
            get { return _SRCID; }
            set { _SRCID = value; }
        }


        string _SRCTYPE;

        public string SRCTYPE
        {
            get { return _SRCTYPE; }
            set { _SRCTYPE = value; }
        }



        string _LOCATION;

        public string LOCATION
        {
            get { return _LOCATION; }
            set { _LOCATION = value; }
        }

        string _SRCPARAM;

        public string SRCPARAM
        {
            get { return _SRCPARAM; }
            set { _SRCPARAM = value; }
        }


    }




    /// <summary>
    /// 用于输出对应的INP文件
    /// </summary>
    public class AermodInp
    {

        //分为CO SO ME RE OU 5段

        string _fileName = "aermod.inp";

        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }


        #region CO


        string _TITLEONE;

        public string TITLEONE
        {
            get { return _TITLEONE; }
            set { _TITLEONE = value; }
        }

        string _TITLETWO;

        public string TITLETWO
        {
            get { return _TITLETWO; }
            set { _TITLETWO = value; }
        }


        string _MODELOPT;

        public string MODELOPT
        {
            get { return _MODELOPT; }
            set { _MODELOPT = value; }
        }

        string _AVERTIME;

        public string AVERTIME
        {
            get { return _AVERTIME; }
            set { _AVERTIME = value; }
        }

        string _POLLUTID;

        public string POLLUTID
        {
            get { return _POLLUTID; }
            set { _POLLUTID = value; }
        }

        string _HALFLIFE;

        public string HALFLIFE
        {
            get { return _HALFLIFE; }
            set { _HALFLIFE = value; }
        }

        string _FLAGPOLE;

        public string FLAGPOLE
        {
            get { return _FLAGPOLE; }
            set { _FLAGPOLE = value; }
        }

        string _RUNORNOT;

        public string RUNORNOT
        {
            get { return _RUNORNOT; }
            set { _RUNORNOT = value; }
        }


        string _ERRORFIL = "ERRORS.OUT";

        public string ERRORFIL
        {
            get { return _ERRORFIL; }
            set { _ERRORFIL = value; }
        }



        #endregion


        #region SO


        List<SOITEM> _lstSOITEM = new List<SOITEM>();

        public List<SOITEM> LstSOITEM
        {
            get { return _lstSOITEM; }
            set { _lstSOITEM = value; }
        }



        #endregion




        #region 书写信息


        protected void WriteCO(StringBuilder sb)
        {
            sb.AppendLine("CO STARTING");


            sb.AppendLine("TITLEONE "+this.TITLEONE);
            sb.AppendLine("TITLETWO "+this.TITLETWO);
            sb.AppendLine("MODELOPT "+this.MODELOPT);
            sb.AppendLine("AVERTIME "+this.AVERTIME);
            sb.AppendLine("POLLUTID "+this.POLLUTID);
            sb.AppendLine("HAFFLIFE "+this.HALFLIFE);

            sb.AppendLine("FLAGPOLE "+this.FLAGPOLE);


            sb.AppendLine("RUNORNOT "+this.RUNORNOT);
            sb.AppendLine("ERRORFIL "+this.ERRORFIL);
           



            sb.AppendLine("CO FINISHED");

 
        }

        protected void WriteSO(StringBuilder sb)
        {
            sb.AppendLine("SO STARTING");


            foreach (SOITEM item in this.LstSOITEM)
            {
                sb.AppendLine("LOCATION "+item.SRCID+" "+item.SRCTYPE+" "+item.LOCATION);
                sb.AppendLine("SRCPARAM " + item.SRCID + " " + item.SRCPARAM);
                
            }

            sb.AppendLine("SRCGROUP ALL");
            sb.AppendLine("SO FINISHED");
 
        }

        protected void WriteME(StringBuilder sb)
        {
 
        }

        protected void WriteRE(StringBuilder sb)
        {
 
        }

        protected void WriteOU(StringBuilder sb)
        {
 
        }



        /// <summary>
        /// 尝试着利用throw exception 获得错误信息
        /// </summary>
        /// <param name="path"></param>
        public void WriteFiles(string path)
        {

            StringBuilder sb = new StringBuilder();

            this.WriteCO(sb);
            this.WriteSO(sb);

            this.WriteME(sb);

            this.WriteRE(sb);

            this.WriteOU(sb);


            string content= sb.ToString();




            FileHelper.WriteFile(path + this._fileName, content);




        }

        #endregion


    }
}
